<?php
	include "public/commom/config.php";//引入配置连接数据库文件
	include "public/commom/thumb.php";//引入缩略图文件
	include "public/commom/commom.php";//引入配置图片文件
	
	if($_POST) {
		$user_id = $_SESSION["user_id"];//用户id
		$username = $_POST["username"];//昵称
		$mobilephone = $_POST["mobilephone"];//手机号码
		$email = $_POST["email"];//邮箱
		$gender = $_POST["gender"];//性别
		$headportrait = $_POST["headportrait"];//头像
		$briefintroduction = $_POST["briefintroduction"];//个人简介
		
		if($_FILES) {//如果有上传头像
			//true
			//头像
			$imgsrc = $_FILES["headportrait"]["tmp_name"];//获取图片临时路径
			$imgname = $_FILES["headportrait"]["name"];//获取图片名称
			$imgsuffix = explode(".", $imgname);//获取图片后缀名
			$ext = array_pop($imgsuffix);//
			$dst = $uploadPath . time().mt_rand(). "." . $ext;//随机生成图片名称
	
			if(move_uploaded_file($imgsrc, $dst)) {//图片上传成功
				//true
				thumb($dst, 200, 200);//生成缩略图
				$headportrait = basename($dst);//获取带后缀名的图片名称
			}
		}
		
		$sql = "UPDATE user SET username = '$username', mobilephone = '$mobilephone', email = '$email', gender = '$gender', headportrait = '$headportrait', briefintroduction = '$briefintroduction' WHERE id = $user_id";//sql语句 - 修改该id的用户信息
		
		$result = mysqli_query($conn, $sql);//result1 - 执行sql语句
		
		$_SESSION["username"] = $username;
		$_SESSION["headportrait"] = $headportrait;
		
		mysqli_close($conn);//关闭数据库连接
			
		header("Location: ./index.php");//跳转页面
	}
?>